#ifndef MOTOR_H
#define MOTOR_H

#include <p89lpc9351.h>
#include "configuration.h"

volatile char lspeed, rspeed;

void InitMotors()
{
    // set pins to output mode
    P1M1 |= MOTOR_LEFT_PIN | MOTOR_RIGHT_PIN;
    P1M2 |= MOTOR_LEFT_PIN | MOTOR_RIGHT_PIN;
}

/*void setMotorSpeed(int motor, int speed)
int motor: Specifies which motor's speed is set
int speed: Speed value in terms of duty cycle
*/
void setMotorSpeed(int motor, int speed)
{
    if (speed < 0) speed = 0;
    if (speed > MAX_MOTOR_SPEED) speed = MAX_MOTOR_SPEED;
    switch (motor)
    {
        case MOTOR_LEFT: lspeed = speed; break;
        case MOTOR_RIGHT: rspeed = speed; break;
        default: break;
    }
}

#endif
